package com.itzzj.controller;

import com.itzzj.common.anno.OperateLog;
import com.itzzj.common.enums.ActionEnum;
import com.itzzj.common.response.Result;
import com.itzzj.common.response.ResultResponse;
import com.itzzj.entity.Person;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "测试类")
@RestController
@RequestMapping("/test")
public class TestController {

    @OperateLog(desc = "保存数据", actionType = ActionEnum.ADMIN_ADD)
    @GetMapping("/save")
    public Result save(@RequestParam Map<String, Object> mapPar, int age) {
        Map<String, String> map = new HashMap<>();
        map.put("name", mapPar.get("name").toString());
        map.put("age", age + "");
        map.put("address", "guangzhou");
        return ResultResponse.success(map);
    }

    @OperateLog(desc = "参数测试", actionType = ActionEnum.WEB_TEST)
    @GetMapping("/param")
    public Result testParams(String name, int age) {
        return ResultResponse.success();
    }

    @OperateLog(desc = "测试全局错误拦截", actionType = ActionEnum.ADMIN_ERROR)
    @GetMapping("/testexception")
    public Result testexception() {
        int i = 1 / 0;
        return ResultResponse.success();
    }

    @OperateLog(desc = "测试数据脱敏",actionType = ActionEnum.ADMIN_GET)
    @GetMapping("/dataDesensitizationTest")
    public Result dataDesensitizationTest(){
        Person person = new Person();
        person.setRealName("不才");
        person.setAddress("广东省广州市天河区岑村");
        person.setPhoneNumber("16692366720");
        person.setIdCard("411503200207235896");
        return ResultResponse.success(person);
    }

}
